#include "mediamanagement.h"

#include <QButtonGroup>
#include <QScroller>
#include <QStandardItemModel>
#include <QDir>
#include <QDateTime>
#include <MainWindow.h>

MediaManagement::MediaManagement(QWidget *parent)
    : QWidget(parent)
{
    initUI();
}

void MediaManagement::initUI()
{
    // 设置背景颜色和全局字体
    setStyleSheet(
        "QWidget {"
        "    background-color: #1F1F1F;"
        "    font-family: '微软雅黑';"
        "}"
        );
    // 创建并设置标签页
    m_tabWidget = new QTabWidget(this);
    m_tabWidget->setDocumentMode(true);
    m_tabWidget->tabBar()->setVisible(false);
    m_tabWidget->setStyleSheet("QTabWidget::pane { border: none; }");

    // 创建页面
    m_imageWidget = new ImageWidget(m_tabWidget);
    m_videoWidget = new VideoWidget(m_tabWidget);

    // 添加页面到标签页
    m_tabWidget->addTab(m_imageWidget, "照片");
    m_tabWidget->addTab(m_videoWidget, "视频");

    // 创建头部区域
    QWidget *headerWidget = new QWidget(this);
    headerWidget->setFixedHeight(60*g_yScale);
    QHBoxLayout *titleLayout = new QHBoxLayout(headerWidget);
    titleLayout->setContentsMargins(28*g_xScale, 0, 28*g_xScale, 0);

    // 创建标题标签
    m_pImageBtn = new TouchButton("照片",this);
    m_pImageBtn->setCheckable(true);
    m_pImageBtn->setChecked(true);
    m_pVideoBtn = new TouchButton("视频",this);
    m_pVideoBtn->setCheckable(true);
    QString style=  QString("QPushButton {"
                    "    background-color: #00000000;"
                    "    color: white ;"
                    "    border: none;"
                    "    border-radius: 4px;"
                    "    font:%1px '微软雅黑';"
                    "}"
                    "QPushButton:checked{"
                    "    color: #0056b3 ;"
                    "}").arg(int(20*g_xScale));
    m_pImageBtn->setStyleSheet(style);
    m_pVideoBtn->setStyleSheet(style);

    m_pButtonGroup = new QButtonGroup(this);
    m_pButtonGroup->setExclusive(true);
    m_pButtonGroup->addButton(m_pImageBtn,0);
    m_pButtonGroup->addButton(m_pVideoBtn,1);
    connect(m_pButtonGroup, SIGNAL(buttonToggled(int,bool)), this, SLOT(onSwitchPage(int,bool)));

    QLabel *label = new QLabel("|",this);
    label->setStyleSheet(
        QString(
        "color: #48494E;"
            "    font:%1px '微软雅黑';"
            ).arg(int(20*g_xScale)));
    label->setFixedWidth(5*g_xScale);
    label->setAlignment(Qt::AlignCenter);

    titleLayout->addWidget(m_pImageBtn);
    titleLayout->addWidget(label);
    titleLayout->addWidget(m_pVideoBtn);
    titleLayout->addStretch();
}

void MediaManagement::onSwitchPage(int nID, bool b)
{
    if(b) {
        m_tabWidget->setCurrentIndex(nID);
    }
}

void MediaManagement::hideEvent(QHideEvent *event)
{
    Q_UNUSED(event);
    m_pImageBtn->setChecked(true);
}


void MediaManagement::resizeEvent(QResizeEvent* event)
{
    QWidget::resizeEvent(event);
    m_tabWidget->setGeometry(0,0,width(),height());
}

